<template>
	<div>
		<a-descriptions class="descri">
			<a-descriptions-item label="应用名称" v-if="iosConfig.name">{{ iosConfig.name }}</a-descriptions-item>
			<a-descriptions-item label="版本号">{{ iosConfig.appVersion }}</a-descriptions-item>
			<a-descriptions-item label="移动端appId">{{ iosConfig.appAppId }}</a-descriptions-item>
			<a-descriptions-item label="版本说明">{{ iosConfig.appVersionNote || '暂无' }}</a-descriptions-item>
			<a-descriptions-item label="bundleId">{{ iosConfig.bundleId }}</a-descriptions-item>
			<a-descriptions-item label="urlScheme：">{{ iosConfig.urlScheme }}</a-descriptions-item>
			<a-descriptions-item label="plist">
				<div @click="downloadFile(iosConfig.plist)" class="file-item"><paper-clip-outlined />{{ iosConfig.plist }}
				</div>
			</a-descriptions-item>
			<!-- <a-descriptions-item label="描述信息">{{ iosConfig.param }}</a-descriptions-item> -->
			<a-descriptions-item v-if="iosConfig.permission" label="名单权限">{{
				iosConfig.permission == '0' ? '全国' : '白名单'
			}}</a-descriptions-item>
			<a-descriptions-item v-if="iosConfig.taskTime" label="应用上线时间">{{ iosConfig.taskTime }}</a-descriptions-item>
			<a-descriptions-item label="下架原因" v-if="showRea">{{ iosConfig.reason }}</a-descriptions-item>
		</a-descriptions>
		<a-descriptions>
			<a-descriptions-item label="应用logo">
				<img class="img-sty" :src="logo" @click="handlePreview(logo)" />
			</a-descriptions-item>
		</a-descriptions>
		<a-descriptions>
			<a-descriptions-item label="参数信息">{{ iosConfig.param || '暂无' }}</a-descriptions-item>
		</a-descriptions>
		<a-modal :visible="previewVisible" :footer="null" @cancel="handleCancel">
			<img alt="example" style="width: 100%" :src="imageUrl" />
		</a-modal>
	</div>
</template>

<script setup name="IosConfig">
import tool from '@/utils/tool'
const datas = inject('detailDate')
const iosConfig = datas.value?.iosPropertiesList[0]

// const iosConfig = {
//     appVersion: '1.0',
//     appVersionNote: '我是说明',
//     packageName: 'asdas',
//     activityName: 'asfdsfs',
//     param: 'miaoshji,',
//     apk: 'asadasda',
//     name: 'sdasd.apk',
//     logo: "[{\"name\":\"微信图片_20230907172856.png\",\"url\":\"2023/9/15/1702512809483665410.png\"}]"
// }
const fileUrl = import.meta.env.VITE_FILE_URL_W
const logo = computed(() => {
	let str = ''
	if (iosConfig.appLogo && iosConfig.appLogo.includes('name') && iosConfig.appLogo.includes('url')) {
		str = `${fileUrl}/${JSON.parse(iosConfig.appLogo)[0].url}`
	}
	return str
})
const showRea = computed(() => {
	let bool = false
	const approvalType = tool.session.get('approvalType')
	const doneStatus = tool.session.get('doneStatus')
	if ((approvalType === '0' || approvalType === '8') && !doneStatus) {
		bool = true
	}
	return bool
})

const imageUrl = ref('')
let previewVisible = ref(false)
const handlePreview = (url) => {
	imageUrl.value = url
	previewVisible.value = true
}
const handleCancel = () => {
	previewVisible.value = false
}
const downloadFile = (item) => {
	const path = `${fileUrl}/${item.url}`
	const name = item.name
	const xhr = new XMLHttpRequest()
	xhr.open('get', path)
	xhr.responseType = 'blob'
	xhr.send()
	xhr.onload = function () {
		if (this.status === 200 || this.status === 304) {
			const fileReader = new FileReader()
			fileReader.readAsDataURL(this.response)
			fileReader.onload = function () {
				const a = document.createElement('a')
				a.style.display = 'none'
				a.href = this.result
				a.download = name
				document.body.appendChild(a)
				a.click()
				document.body.removeChild(a)
			}
		}
	}
}
</script>

<style lang="less" scoped>
.descri {
	margin-top: 10px;
}

.img-sty {
	width: 104px;
	height: 104px;
	cursor: pointer;
}

.file-item {
	color: rgb(89, 89, 89);
	cursor: pointer;
}

.file-item:hover {
	color: var(--primary-color);
}
</style>

